/*
 * @Author: wwssaabb
 * @Date: 2021-06-08 16:09:58
 * @LastEditTime: 2021-06-08 17:40:37
 * @FilePath: \demo\koa2_demo\middleware\koa_response_header.js
 */

//设置响应头的中间件
//第二层中间件
//获取mime类型 application/json
//设置响应头 Content-Type:application/json;charset=UTF-8

module.exports=async (ctx,next)=>{
  const contentType='application/json;charset=UTF-8'
  ctx.set('Content-Type',contentType)

  //允许跨域
  ctx.set('Access-Control-Allow-Origin','*')
  ctx.set('Access-Control-Allow-Methods','OPTIONS,GET,POST,PUT,DELETE')
  await next()
}
